//-----------------------------------------------------------------------------
// File: ShapeUiService.cs
//
// Copyright (c) Dmitry Shuklin. All rights reserved.
//-----------------------------------------------------------------------------
using System;

namespace ObjectiveDraw.Platform
{
	/// <summary>
	/// Summary description for ShapeUiService.
	/// </summary>
	public class ShapeUiService : Cerebrum.Windows.Forms.Reflection.UiServiceDescriptor
	{
		public ShapeUiService()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		public ObjectiveDraw.Platform.Application DrawerApplication
		{
			get
			{
				return this.DomainContext.Properties[ObjectiveDraw.Platform.Application.m_ApplicationProperty] as ObjectiveDraw.Platform.Application;
			}
		}

		/*private Cerebrum.Windows.Forms.IUiControl FindControl(Cerebrum.Windows.Forms.IUiCommand command, System.Type type)
		{
			if(command==null) return null;
			foreach(Cerebrum.Windows.Forms.IUiControl ctl in command.Controls)
			{
				if(type.IsAssignableFrom(ctl.GetType()))
				{
					return ctl;
				}
			}
			return null;
		}*/
		public override bool CommandActivated(Cerebrum.IConnector message, object sender, object argument)
		{
			string name = ((Cerebrum.Reflection.MessageDescriptor)message.Component).Name;

			switch(name)
			{
				case "Init":
				{
					return true;
				}
				case "ObjectiveDraw.ChartScrollerMouseHandler":
				{
					ObjectiveDraw.Platform.Application _app = this.DrawerApplication;
					_app.ShapeDrawerMouseHandler.IsLocked = false;
					_app.ActiveMouseHandler = _app.ChartScrollerMouseHandler;
					_app.SelectBandItem(sender as Cerebrum.Windows.Forms.IUiControl /* FindControl(sender as Cerebrum.Windows.Forms.IUiCommand, typeof(ObjectiveDraw.Platform.DrawerBandItem)) */ );
					return true;
				}
				default:
				{
					//TODO check message
					ObjectiveDraw.Platform.Application _app = this.DrawerApplication;
					_app.ShapeDrawerMouseHandler.ActiveShapeComponentId = name;
					if((System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Shift) != 0)
					{
						_app.ShapeDrawerMouseHandler.IsLocked = true;
					}
					else
					{
						_app.ShapeDrawerMouseHandler.IsLocked = false;
					}
					_app.ActiveMouseHandler = _app.ShapeDrawerMouseHandler;
					_app.SelectBandItem(sender as Cerebrum.Windows.Forms.IUiControl /* FindControl(sender as Cerebrum.Windows.Forms.IUiCommand, typeof(ObjectiveDraw.Platform.DrawerBandItem)) */ );
					return true;
				}
			}
			//--return base.CommandActivated(message, sender, argument);
		}
	}
}